﻿using System.Collections.ObjectModel;
using G.Model;

namespace G.Runtime
{
    public class GameElementActions : 
        KeyedCollection<GameLocation, GameElementAction>
    {
        public delegate void ActionsChangedHandler();
        public event ActionsChangedHandler ActionsChangedEvent;

        public new void Add(GameElementAction action)
        {
            base.Add(action);
            if (ActionsChangedEvent != null)
            {
                ActionsChangedEvent();
            }
        }

        public void AddActions(GameElementAction[] actions)
        {
            Clear();
            foreach (GameElementAction action in actions)
            {
                Add(action);
            }
            if (ActionsChangedEvent != null)
            {
                ActionsChangedEvent();
            }
        }

        public new void Clear()
        {
            base.Clear();
            if (ActionsChangedEvent != null)
            {
                ActionsChangedEvent();
            }
        }

        protected override GameLocation GetKeyForItem(GameElementAction item)
        {
            return item.Destination;
        }

    }
}
